package com.example.flutter_youren

import android.app.Activity
import android.content.Intent
import android.util.Log
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

class MethodCallHandlerImpl(var act: Activity) : MethodChannel.MethodCallHandler {
    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
        when (call.method) {
            "openNativePage1" -> {
                val intent = Intent(act, AndroidNativeActivity::class.java)
                val value = call.arguments as Map<*, *>
                intent.putExtra("startNativePageNum", (value["startNativePageNum"] ?: 1) as Int)
                act.startActivity(intent)
                result.success(0)
            }
            "startFlutterPageName" -> {
                val startFlutterPageName = act.intent.extras?.getString("startFlutterPageName")
                val nativeNum = act.intent.extras?.getInt("startNativePageNum")
                Log.e(NativeConstant.TAG, "startFlutterPageName = $startFlutterPageName")
                val map = mapOf(
                    "startFlutterPageName" to startFlutterPageName,
                    "startNativePageNum" to nativeNum
                )
                result.success(map)
            }
            "closeFlutterPage" -> {
                act.finish()
                result.success(0)
            }
            else -> {
                result.notImplemented()
            }
        }
    }
}